// pages/application-number-reality/application-number-reality.js
const app = getApp()
import util from "../../utils/util.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    prevShow: true,
    prevDate: '',
    prevNumber: '',
    realityNumber: '',
    currentDate: new Date().getTime() + 86400000,
    dateShow:false,
    expend:false,
    foodList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getShufflingsData()
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  handelShowDate(){
    this.setData({ dateShow:true})
  },
  onClose(){
    this.setData({ dateShow: false })
  },
  dateConfirm(e){
    this.setData({ prevDate: util.formatTime(new Date(e.detail)).substring(0, 16) })  
    this.setData({ dateShow: false })
  },
  formatDate  (date)  {
    date = new Date(date)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    return year + '-' + month + '-' + day
  },
  handelConfirm(){
    const { prevDate, prevNumber}=this.data
  
    if (!prevNumber ||!prevDate){
      wx.showToast({
        title: '请填写用餐时间与用餐人数',
        icon: 'none',
      })
        return
    }


    app.globalData.estimatedTime = prevDate
    app.globalData.estimatedNum = prevNumber 
    

    app.reqFetch.temporaryordersaveOrder({
     sign:0,
      mealTime: prevDate,
      estimateNum: prevNumber,
    }, (res) => {
      wx.navigateTo({
        url: '/pages/supply-menu/supply-menu',
      })
    })



  },
  addMore(){

    this.setData({ expend: true })
  },
  numChnage(e){
    console.log(e)
    this.setData({ prevNumber: e.detail.value })
   
  },

  getShufflingsData() {
    app.reqFetch.stockorderHome({
      page: 1,
      limit: 10
    }, (res) => {
      console.log(res)
      this.setData({
        foodList: res.list.list
      })
    })
  },
  handleCancel() {
    wx.redirectTo({
      url: '/pages/chef-home/chef-home',
    })
  }
})